import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { getWeekMonthQuarterYear } from '/@/utils';
//列表数据
export const columns: BasicColumn[] = [
   {
    title: '值班日期',
    align:"center",
    dataIndex: 'dutyDate',
    customRender:({text}) =>{
      text = !text ? "" : (text.length > 10 ? text.substr(0,10) : text);
      if(text) {
        return getWeekMonthQuarterYear(text)['default'];
      } else {
        return text;
      }
    },
   },
   {
    title: '值班类型',
    align:"center",
    dataIndex: 'dutyType_dictText'
   },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
     {
      label: "值班日期",
      field: "dutyDate",
      component: 'RangePicker',
      componentProps: {
        picker: 'default',
        valueType: 'Date',
      },
      //colProps: {span: 6},
	},
	{
      label: "值班类型",
      field: "dutyType",
      component: 'JDictSelectTag',
      componentProps:{
          dictCode:"duty_type"
      },
      //colProps: {span: 6},
 	},
];
//查询数据
export const searchPersonFormSchema: FormSchema[] = [
	{
      label: "值班开始时间",
      field: "dutyStartTime",
      component: 'TimePicker',
      componentProps: {
        valueFormat: 'HH:mm',
        format:'HH:mm'
      },
      //colProps: {span: 6},
 	},
	{
      label: "值班结束时间",
      field: "dutyEndTime",
      component: 'TimePicker',
      componentProps: {
        valueFormat: 'HH:mm',
        format:'HH:mm'
      },
      //colProps: {span: 6},
 	},
	{
      label: "值班人",
      field: "dutyUserId",
      component: 'JSelectUserGbiac',
      componentProps: {
        multiple: false
      },
 	},
	{
      label: "席位",
      field: "seatName",
      component: 'JPopup',
      componentProps: ({ formActionType }) => {
          const {setFieldsValue} = formActionType;
          return{
              setFieldsValue:setFieldsValue,
              code:"gbiac_seat",
              fieldConfig: [
                  { source: 'id', target: 'seatId' },
                  { source: 'seat_name', target: 'seatName' },
              ],
              multi:false
          }
      },
 	},
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '值班日期',
    field: 'dutyDate',
    component: 'DatePicker',
    componentProps: {
        picker: 'default',
      valueFormat: 'YYYY-MM-DD'
    },
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入值班日期!'},
          ];
     },
  },
  {
    label: '值班类型',
    field: 'dutyType',
    component: 'JDictSelectTag',
    componentProps:{
        dictCode:"duty_type"
     },
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入值班类型!'},
          ];
     },
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];

//子表列表数据
export const gbiacDutyManagementPersonColumns: BasicColumn[] = [
   {
    title: '值班开始时间',
    align:"center",
    dataIndex: 'dutyStartTime'
   },
   {
    title: '值班结束时间',
    align:"center",
    dataIndex: 'dutyEndTime'
   },
   {
    title: '值班人',
    align:"center",
    dataIndex: 'dutyUserId_dictText'
   },
   {
    title: '席位',
    align:"center",
    dataIndex: 'seatName'
   },
];
//子表表单数据
export const gbiacDutyManagementPersonFormSchema: FormSchema[] = [
  // TODO 子表隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
  {
    label: '值班开始时间',
    field: 'dutyStartTime',
    component: 'TimePicker',
    componentProps: {
      valueFormat: 'HH:mm',
      format:'HH:mm'
    },
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入值班开始时间!'},
          ];
     },
  },
  {
    label: '值班结束时间',
    field: 'dutyEndTime',
    component: 'TimePicker',
    componentProps: {
      valueFormat: 'HH:mm',
      format:'HH:mm'
    },
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入值班结束时间!'},
          ];
     },
  },
  {
    label: '值班人',
    field: 'dutyUserId',
    component: 'JSelectUserGbiac',
      componentProps: {
      multiple: false,
      labelKey:'username',
    },
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入值班人!'},
          ];
     },
  },
  {
    label: '席位',
    field: 'seatName',
    component: 'JPopup',
    componentProps: ({ formActionType }) => {
        const {setFieldsValue} = formActionType;
        return{
            setFieldsValue:setFieldsValue,
            code:"gbiac_seat",
            fieldConfig: [
                { source: 'id', target: 'seatId' },
                { source: 'seat_name', target: 'seatName' },
            ],
            multi:true
        }
    },

    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入席位!'},
          ];
     },
  },
];

// 高级查询数据
export const superQuerySchema = {
  dutyDate: {title: '值班日期',order: 0,view: 'date', type: 'string',},
  dutyType: {title: '值班类型',order: 1,view: 'list', type: 'string',dictCode: 'duty_type',},
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}